#include <iostream>
#include "main_page.h"
#include "touch.h"
#include "bmp.h"
#include "lcd.h"
#include "tcp_socket.h"

// EXPLOSIVE_PACKAGE_BUTTON 
// NANCHANG_MIXED_RICE_NOODLES_BUTTON 
// CLAY_POT_SOUP_BUTTON 
// NANCHANG_SNACKS_BUTTON 
// BEVERAGE_BUTTON 

using namespace std;

//目前已知bug
//1 页数没控制
//2 没点击上下面七个按钮，vector为空，没初始化



int main()
{
    //创建通信的套接字
    // TcpSocket tcp;

    //连接服务器IP port
    // int ret = tcp.connectToHost("192.168.1.75", 10000);
    // if(ret == -1){
    //     return -1;
    // }
    
    //初始化主页面
    Bmp bmp("./res/interfaces/main_interface.bmp");
    bmp.show();
    
    MainPage main_page;
    main_page.lists_init();
    main_page.dish_name_price_init();
    main_page.tcp_init();
    //main_page.lists_show();
    //界面显示的八个位置再创一个八个大小数组，购物车一个链表
    Touch touch;
    int x, y;
    //当前的主界面的菜种类，默认为爆款套餐
    Dish_Type_E now_dish_type = Dish_Type_E::Explosive_package;
    while(1){
        main_page.totle_price_calculate();
        main_page.totle_price_show();
        cout << "购物车所有菜总金额" << main_page.get_total_price() << endl;
        touch.wait(x, y);
        if(DISH_TYPE_BUTTON){//进入菜品类型选择界面
            if(EXPLOSIVE_PACKAGE_BUTTON){
                main_page.dish_type_click(Dish_Type_E::Explosive_package);
                now_dish_type = Dish_Type_E::Explosive_package;
            }else if(NANCHANG_MIXED_RICE_NOODLES_BUTTON){
                main_page.dish_type_click(Dish_Type_E::Nanchang_mixed_rice_noodles);
                now_dish_type = Dish_Type_E::Nanchang_mixed_rice_noodles;
            }else if(CLAY_POT_SOUP_BUTTON){
                main_page.dish_type_click(Dish_Type_E::clay_pot_soup);
                now_dish_type = Dish_Type_E::clay_pot_soup;
            }else if(NANCHANG_SNACKS_BUTTON){
                main_page.dish_type_click(Dish_Type_E::Nanchang_snacks);
                now_dish_type = Dish_Type_E::Nanchang_snacks;
            }else if(BEVERAGE_BUTTON){
                main_page.dish_type_click(Dish_Type_E::beverage);
                now_dish_type = Dish_Type_E::beverage;
            }
        }

        //点击上一页下一页的if判断
        if(PREV_NEXT_PAGE_BUTTON){
            if(PREV_PAGE_BUTTON){
                main_page.prev_next_click(now_dish_type, Page_Type_E::Prev_page);
            }else if(NEXT_PAGE_BUTTON){
                main_page.prev_next_click(now_dish_type, Page_Type_E::Next_page);
            }
        }
        //点击中间八个菜的+-判断
        if(DISH_MINUS_ADD_BUTTON_UP){
            if(DISH_MINUS_BUTTON_1){
                main_page.minus_from_shopping_cart(0);
            }else if(DISH_ADD_BUTTON_1){
                main_page.add_to_shopping_cart(0);
            }else if(DISH_MINUS_BUTTON_2){
                main_page.minus_from_shopping_cart(1);
            }else if(DISH_ADD_BUTTON_2){
                main_page.add_to_shopping_cart(1);
            }else if(DISH_MINUS_BUTTON_3){
                main_page.minus_from_shopping_cart(2);
            }else if(DISH_ADD_BUTTON_3){
                main_page.add_to_shopping_cart(2);
            }else if(DISH_MINUS_BUTTON_4){
                main_page.minus_from_shopping_cart(3);
            }else if(DISH_ADD_BUTTON_4){
                main_page.add_to_shopping_cart(3);
            }
        }
        if(DISH_MINUS_ADD_BUTTON_DOWN){
            if(DISH_MINUS_BUTTON_5){
                main_page.minus_from_shopping_cart(4);
            }else if(DISH_ADD_BUTTON_5){
                main_page.add_to_shopping_cart(4);
            }else if(DISH_MINUS_BUTTON_6){
                main_page.minus_from_shopping_cart(5);
            }else if(DISH_ADD_BUTTON_6){
                main_page.add_to_shopping_cart(5);
            }else if(DISH_MINUS_BUTTON_7){
                main_page.minus_from_shopping_cart(6);
            }else if(DISH_ADD_BUTTON_7){
                main_page.add_to_shopping_cart(6);
            }else if(DISH_MINUS_BUTTON_8){
                main_page.minus_from_shopping_cart(7);
            }else if(DISH_ADD_BUTTON_8){
                main_page.add_to_shopping_cart(7);
            }
        }

        //点击下单按钮
        if(ORDER_BUTTON){
            //创建一个1024大小的char数组，用来存储购物车数据的
            char order_data[1024] = {0};
            main_page.order_click();
            main_page.order_clear();
        }

        //点击购物车按钮
        if(SHOP_CAR_BUTTON){
            main_page.shop_car_interface();
        }
    }
    return 0;
}
